package com.zyl.king.controller;

import com.zyl.king.VO.OrderVO;
import com.zyl.king.result.Result;
import com.zyl.king.service.IOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author zyl
 * @since 2025-01-05
 */
@Tag(name = "订单管理", description = "订单")
@RestController
@RequestMapping("/king/order")
public class OrderController {

    @Resource
    private IOrderService orderService;

    @Operation(summary = "添加订单", description = "添加订单")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "Successfully"),
            @ApiResponse(responseCode = "404", description = "err")
    })
    @PostMapping("/addOrder")
    public Result addOrder(@RequestBody OrderVO vo){
        Result result = orderService.addOrder(vo);
        return result;
    }

    @Operation(summary = "查询订单订单", description = "查询")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "Successfully"),
            @ApiResponse(responseCode = "404", description = "err")
    })
    @PostMapping("/queryOrder")
    public Result queryOrder( @Parameter(description = "用户名", required = false)
                                  @RequestParam(required = false) String userName) {
        return orderService.queryOrder(userName);
    }

    @GetMapping("/test")
    public String test() {
        return "Test successful!";
    }
}
